1822D - Super-Permutation - CodeForces Solution


constructive algorithms math *1200

Please click on ads to support us..

C++ Code:

// url: https://codeforces.com/problemset/problem/1822/D
// memory limit: 256MB
// time limit: 2000s
#include <bits/stdc++.h>
using namespace std;

typedef long long big;
#define pb push_back
typedef long double ludo;
#define fl(i,a,n) for(int i=a;i<n;i++)
#define all(x) (x).begin(), (x).end()

template <typename T>
ostream& operator <<(ostream& ostream , vector<T> &vec)
{ 
	for(auto x:vec) cout<<x<<' ';
	return ostream;
}

template <typename T>
ostream& operator <<(ostream& ostream , pair<T,T> &x)
{ 
	cout<<x.first<<' '<<x.second;
	return ostream;
}

template <typename T>
istream& operator >> (istream& istream , vector<T> &vec)
{
	for(int i=0;i<vec.size();i++)
	{
		cin>>vec[i];
	}
	return istream;
}

int gcd(int a, int b)
{
	return b == 0 ? a : gcd(a,a%b);
}

void solve()
{
	int n;cin>>n;
	if(n==1)
	{
		cout<<1;
		return;
	}
	if(n%2!=0)
	{
		cout<<"-1";
		return;
	}
	cout<<n<<' '<<n-1<<' ';
	int l = 1;
	int r = n-2;
	int pos = n-1;
	for(int i=0;i<n-2;i+=2)
	{
		cout<<n-pos+l<<' '<<r-l<<' ';
		pos=r;
		r--;l++;
	}


}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	big test;
	cin>>test;
	while(test--)
	{
		solve();
		cout<<'\n';
	}
}


Comments

Submit
1 Comments
  • 25/4/2024 12:54 - Asia/Dhaka

4

4

5

6

7

8

 


More Questions

553A - Kyoya and Colored Balls
1364A - XXXXX
1499B - Binary Removals
1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating